package com.lingx.service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.lingx.model.impl.DefaultEntity;
import com.lingx.model.impl.DefaultMethod;
@Component("lingxMethodService")
public class MethodService {
	@Resource
	private List<DefaultMethod> methods;
	@Resource
	private ModelService modelService;
	public DefaultMethod getMethod(String mcode,String ecode) {
		DefaultEntity entity=this.modelService.getEntity(ecode);
		return this.getMethod(mcode, entity);
	}
	public DefaultMethod getMethod(String mcode,DefaultEntity entity) {
		DefaultMethod ret=null;
		for(DefaultMethod m:entity.getMethods().getList()) {
			if(mcode.equals(m.getCode())) {
				ret=m;
				break;
			}
		}
		if(ret==null)
		for(DefaultMethod m:methods) {
			if(mcode.equals(m.getCode())) {
				ret=m;
				//ret.setFields(entity.getFields());//因为多程处理时，线程不安全，所以业务处理直接取entity.getFields()
				break;
			}
		}
		return ret;
	}
	public List<DefaultMethod> getDefaultMethods() {
		return methods;
	}
	public boolean defaultMethodContains(String mcode) {
		boolean b=false;
		for(DefaultMethod m:methods) {
			if(m.getCode().equals(mcode)) {
				b=true;break;
			}
		}
		return b;
	}
}
